package org.jash.mvp2206.user;

import org.jash.mvp2206.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class LoginPresenter extends BasePresenter<Construct.ILoginView> implements Construct.ILoginPresenter {
    private Construct.ILoginModel model = new LoginModel();
    @Override
    public void login(String username, String password) {
        disposable.add(model.login(username, password).observeOn(AndroidSchedulers.mainThread())
                .subscribe(r -> {
                    if (isAttach()) {
                        if (r.getCode() == 0) {
                            getWhoView().loginSuccess(r.getData());
                        } else {
                            throw new RuntimeException(r.getMsg());
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().loginFailure(t);
                    }
                }));
    }
}
